package com.baidu.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.baidu.constant.MessageConstant;
import com.baidu.entity.Result;
import com.baidu.pojo.Setmeal;
import com.baidu.service.SetMealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetMealController {

	@Reference
	private SetMealService setMealService;

	@RequestMapping("/getSetmeal")
	public Result findAll(){

		try {
			List<Setmeal> list= setMealService.findAll();
			return new Result  (true,MessageConstant.GET_SETMEAL_LIST_SUCCESS,list);
		} catch (Exception e) {
			return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
		}


	}


	@RequestMapping("/findById")
	public Result findById(Integer id){

		try {
			Setmeal setmeal=setMealService.findById(id);

			System.out.println(setmeal);

			return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
		} catch (Exception e) {
			return  new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
		}

	}

//	订单页面经常被访问，且操作数据的代价比较大，要操作多条SQL语句。所以单独写个方法，单独封装前端所需的参数。
	@RequestMapping("/findByIdOnlySetmeal")
	public Result findByIdOnlySetmeal(String id){

		try {
			Setmeal setmeal=setMealService.findByIdOnlySetmeal(Integer.parseInt(id));

			System.out.println(setmeal);

			return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
		} catch (Exception e) {
			return  new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
		}

	}





}
